<script src="/login/status"></script>
<!--同步的发起get请求-->
<script>
  //如果为false,则代表未登录,强行跳转到登录页
  if (!isLogin) location.href = 'login.html'
</script>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
</head>

<body>
  <div class="login">
    <div class="login-wrap">
      <img class="avatar" src="../assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
          <strong>错误！</strong> 用户名或密码错误！
        </div> -->
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" class="form-control" placeholder="密码">
      </div>
      <button class="btn btn-primary btn-block" id="loginBtn">登 录</button>
    </div>
  </div>

  <!--  引入jquery-->
  <script src="../assets/vendors/jquery/jquery.min.js"></script>
  <script>
    //点击登录按钮,发起登录请求
    $('#loginBtn').click(function () {
      //获取邮箱和密码值,做一个前端校验
      let email = $("#email").val()
      let password = $('#password').val()
      if (email.trim().length === 0) {
        alert("请输入邮箱")
        return
      }
      if (password.trim().length === 0) {
        alert("请输入密码")
        return
      }
      //已经输入用户名和密码,发起ajax请求
      $.ajax({
        type: 'post',
        url: '/login',
        data: { email: email, password: password },
        success: function (response) {
          //console.log(response)
          //页面跳转到后台首页
          location.href = 'index.html'
        },
        error: function () {
          alert("用户名或密码错误")
        }
      })
    })
  </script>
</body>

</html>